package com.atguigu.lease.web.app.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2025/1/10 11:33
 * @注释
 */
@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        for (ItemType itemType : ItemType.values()) {
            if (itemType.getCode().equals(Integer.valueOf(source))) {
                return itemType;
            }
        }
        throw new IllegalArgumentException("code非法");
    }
}
